package UpDownload;
import java.io.BufferedOutputStream;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Proposal.ProposalItem;

@WebServlet("/ProposalDownloadServlet")
public class ProposalDownloadServlet extends HttpServlet  {
    private static final long serialVersionUID = 1L;
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BufferedOutputStream output = null;
        try {
            ProposalItem fileModel = (ProposalItem)request.getAttribute("fileModel");
            response.setContentType("application/octet-stream");
            response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileModel.getFileName().getBytes("utf-8"),"8859_1") + ";" );
            output = new BufferedOutputStream(response.getOutputStream());
            output.write(fileModel.getData());
        } catch (Exception e) {
            throw new ServletException(e);
        } finally {
            try {
                if (output != null) output.close();
            } catch (Exception e) {}
        }
    }

}
